<?php 
/**
 * 处理用户的求租，求购，卖房 租房的委托入库
 */
namespace Wdl\model;
use Wdl\validate\ValidateException;
use Wdl\helper\FrontHelper; 
use Wdl\validate\demandValidate;

 class demand extends base
{
    
    public function index()
    {  
        $openid = $this->openid;
        $uid = $this->uid;
        $send_type = $this->_GPC['send_type'] ;
        try{
            $check = demandValidate::make();           
            if($send_type== 'chushou' || $send_type == 'chuzu'){
                
                $data = $check ->scene('sell')->check($this->_GPC);
                $village_name = $data['village_name'];
                if($send_type =='chushou')
                    $unit = '万元';
                else 
                    $unit = '元/月';
            }else{
                
                $data = $check ->scene('xuqiu')->check($this->_GPC);
                $village_name = $data['area_quan'];
                if($send_type == 'qiugou') 
                    $unit = '万元';
                else 
                    $unit = '元/月';
            }
      
               
 
        }catch(ValidateException $e){

            return $this->msg(1, $e->getMessage() );
        }

        $save = [
            'uniacid'=> $this->uniacid, 
            'openid' => $openid,
            'uid' => $uid,
            'created_time' => TIMESTAMP, 
            'orign_json' => json_encode($data),
            'village' => $village_name,
            'nickname'=> $data['nickname'],
            'huxing' => isset($data['huxing']) ? $data['huxing'] :"",
            'mobile' => $data['mobile'],
            'price' => $data['price'],
            'price_unit' => $unit,
            'send_type'=>  $data['send_type'] ,
        ];
        if(! FrontHelper::checkPostContent($save)){
            return $this->msg(1, '安全检查失败' );
        }
        pdo_insert("kbwdl_demand", $save);
        return $this->msg(0, '成功', $save );
    }
}
